package com.cmwa.solution.sys.msg.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cmwa.solution.base.dao.BaseDao;
import com.cmwa.solution.base.entity.Page;
import com.cmwa.solution.base.entity.SearchParam;
import com.cmwa.solution.base.service.impl.BaseServiceImpl;
import com.cmwa.solution.sys.msg.dao.IMsgPublicEmailDao;
import com.cmwa.solution.sys.msg.service.IMsgPublicEmailService;
import com.cmwa.solution.sys.msg.vo.MsgPublicEmailVo;

@Service
@SuppressWarnings({"rawtypes", "unchecked"})
public class MsgPublicEmailServiceImpl extends BaseServiceImpl<MsgPublicEmailVo>  implements IMsgPublicEmailService {
	@Resource
	private IMsgPublicEmailDao dao;

	@Override
	public BaseDao<MsgPublicEmailVo> getDao() {
		return dao;
	}

	@Override
	public List<MsgPublicEmailVo> queryAllPublicEmail() {
		return dao.queryAllPublicEmail();
	}

	@Override
	public List<MsgPublicEmailVo> queryAllConfPublicEmail() {
		return dao.queryAllConfPublicEmail();
	}

	@Override
	public List<MsgPublicEmailVo> queryPublicEmailByConfId(Map map) {
		return dao.queryPublicEmailByConfId(map);
	}
	
	@Override
	public List<MsgPublicEmailVo> queryAllPublicEmailByName(SearchParam sp) {
		return dao.queryAllPublicEmailByName(sp);
	}

	@Override
	public int deletePublicEmailByConfId(Map map) {
		return dao.deletePublicEmailByConfId(map);
	}

	@Override
	public int insertPublicEmailByConfId(String confId,String type,String[] pubcIds) {
		if(confId!=null && !"".equalsIgnoreCase(confId.trim()) && pubcIds!=null && pubcIds.length>0){
			List<Map> params=new ArrayList<Map>();
			for(int i=0;i<pubcIds.length;i++){
				Map p=new HashMap();
				p.put("CONF_ID", confId);
				p.put("EMAIL_ID", pubcIds[i]);
				p.put("EMAIL_TYPE", type);
				params.add(p);
			}
			//return dao.insertPublicEmailByConfId(params);
			try {
				batchOperateData("com.cmwa.cbp.sys.msg.dao.IMsgPublicEmailDao.insertPublicEmailByConfId", params, 50);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return 0;
	}

	@Override
	public Page<MsgPublicEmailVo> publicEmailListPage(SearchParam sp) {
		List<MsgPublicEmailVo> items = dao.publicEmailListPage(sp);
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}
	
	@Override
	public MsgPublicEmailVo queryById(String id) {
		return dao.queryById(id);
	}
}
